package com.itheima.service.impl;

import com.itheima.mapper.ChatManagementMapper;
import com.itheima.pojo.Properties;
import com.itheima.service.ChatManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.bus.endpoint.RefreshBusEndpoint;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ChatManagementServiceImpl implements ChatManagementService {
    @Autowired
    private ChatManagementMapper chatManagementMapper;

    @Autowired
    private RefreshBusEndpoint refreshBusEndpoint;

    @Override
    public List<Properties> findAll() {
        return chatManagementMapper.findAll();
    }

    @Override
    public void updateOne(Integer id) {
        Integer valueById = chatManagementMapper.findValueById(id);
        Integer value = valueById==1 ? 0 : 1;
        Properties prop = Properties.builder().id(id).value(value).build();
        chatManagementMapper.updateByProp(prop);
        refreshBusEndpoint.busRefresh();
    }
}
